<template>
  <v-chart class="chart" :option="option" />
</template>
<script>
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { LineChart, BarChart } from "echarts/charts";
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  ToolboxComponent,
  GridComponent,
} from "echarts/components";
import VChart, { THEME_KEY } from "vue-echarts";
use([
  CanvasRenderer,
  BarChart,
  TitleComponent,
  TooltipComponent,
  ToolboxComponent,
  LegendComponent,
  LineChart,
  GridComponent,
]);

export default {
  name: "Echarts",
  components: {
    VChart,
  },
  props: ["optionData"],
  provide: {
    [THEME_KEY]: "", // 背景色 dark
  },
  data() {
    return {
      option: {
        title: this.optionData.title,
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        legend: {
          data: this.optionData.legendData,
        },
        toolbox: {
          show: this.optionData.toolbox,
          orient: "vertical",
          left: "right",
          top: "center",
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ["line", "bar", "stack", "tiled"] },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        xAxis: [
          {
            type: "category",
            axisTick: { show: false },
            data: this.optionData.xAxisData,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: this.optionData.seriesData
      },
    };
  },
};
</script>
<style scoped>
.chart {
  height: 300px;
}
</style>
